package com.haoting.mamba.player.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.haoting.mamba.player.entity.PlayerInformationEntity;
import com.haoting.mamba.player.service.PlayerInformationService;
import com.haoting.common.utils.PageUtils;
import com.haoting.common.utils.R;



/**
 * 
 *
 * @author tanghao
 * @email 767417609@qq.com
 * @date 2021-03-14 20:47:39
 */
@RestController
@RequestMapping("player/playerinformation")
public class PlayerInformationController {
    @Autowired
    private PlayerInformationService playerInformationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = playerInformationService.queryPage(params);

        return R.ok().put("page", page);
    }

    //根据id返回名字
    @GetMapping("/findName/{id}")
    public R findName(@PathVariable("id") String id){
        PlayerInformationEntity page = playerInformationService.getById(id);
        String name = page.getName();
        return R.ok().put("name", name);
    }

    @GetMapping("/getAll")
    public R getAll(){
        List<PlayerInformationEntity> list = playerInformationService.list();
        return R.ok().put("playerInformation",list);
    }

    /**
     * 信息
     */
    @PostMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
		PlayerInformationEntity playerInformation = playerInformationService.getById(id);

        return R.ok().put("playerInformation", playerInformation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody PlayerInformationEntity playerInformation){
		String id = playerInformationService.saveInformation(playerInformation);
        return R.ok().put("id",id);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody PlayerInformationEntity playerInformation){
		playerInformationService.updateById(playerInformation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] ids){
		playerInformationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
